package org.itzheng.database.dao;

import org.itzheng.database.entity.History;

import java.util.List;

import androidx.room.Dao;
import androidx.room.Query;

/**
 * Title:历史记录操作<br>
 * Description: <br>
 *
 * @email ItZheng@ZoHo.com
 * Created by itzheng on 2020-6-30.
 */
@Dao
public interface HistoryDao extends BaseDao<History> {
    @Query("select * from History where fUserID=:fUserID and fType=:fType order by _id desc")
    List<History> getItemsByType(int fUserID, int fType);

    /**
     * 删除多余的数据，只保存10条数据
     * 可以每次 insert 完后执行一次
     *
     * @return
     */
    @Query("delete from History where fUserID =:fUserID and " +
            "_id not in(select _id from History order by _id desc limit 10)")
    int deleteOtherData(int fUserID);

    @Query("select * from history where fUserID=:fUserID and fType=:fType and fKeyword =:fKeyword")
    History getItem(int fUserID, int fType, String fKeyword);
}
